package com.bosch.in.rtp1.ept.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.bosch.in.rtp1.ept.constant.DurationColorConstant;
import com.bosch.in.rtp1.ept.dao.DurationColorConDao;
import com.bosch.in.rtp1.ept.model.dto.DurationColorCon;
import com.bosch.in.rtp1.ept.util.SQLStatementLoader;

/**
 * Concrete JDBC implementation of DurationColorConDao. 
 * Provide actions for updating/loading on Duration Color Condition table.
 * @author LIV1HC
 *
 */
public class DurationColorConJDBCDao extends GenericDao implements DurationColorConDao{

	/**
	 * Constructor to inject connection
	 * @param con	DB connection
	 */
	public DurationColorConJDBCDao(Connection connection) {
		super(connection);
	}

	@Override
	public DurationColorCon getDuratonColCon() throws SQLException {
		String queryString = SQLStatementLoader.getDurColSelect();
		ResultSet resultSet = executeQuery(queryString,null);
		DurationColorCon durColCon = new DurationColorCon();
		if (resultSet.next())
		{
			durColCon.setId(resultSet.getInt(DurationColorConstant.ID));
			durColCon.setRedColVal(resultSet.getFloat(DurationColorConstant.RED_COLOR_VAL));
			durColCon.setRedColOp(resultSet.getInt(DurationColorConstant.RED_COLOR_OP));
			durColCon.setYellowColVal(resultSet.getFloat(DurationColorConstant.YELLOW_COLOR_VAL));
			durColCon.setYellowColOp(resultSet.getInt(DurationColorConstant.YELLOW_COLOR_OP));
		}
		// close statement, result set
		resultSet.close();
		close();
		return durColCon;
	}

	@Override
	public boolean updateColorCol(DurationColorCon durColCon) throws SQLException
			{
		String queryString = SQLStatementLoader.getDurColUpdate();
		Object params[] = new Object[4];
		params[0] = durColCon.getRedColVal();
		params[1] = durColCon.getRedColOp();
		params[2] = durColCon.getYellowColVal();
		params[3] = durColCon.getYellowColOp();
		
		return executeUpdate(queryString, params);
	}

	

}
